package main

import (
	"github.com/gorhill/cronexpr"
	"log"
	"time"
)

// 代表一个任务
type CronJob struct {
	name string
	expr *cronexpr.Expression
	nextTime time.Time	// expr.Next(now)
}

func (job *CronJob) Exec () error {
	log.Printf("[%s] is exec",job.name)
	return nil
}

func (job *CronJob) Check (u time.Time) bool {
	ret:=false
	if job.nextTime.Before(u) || job.nextTime.Equal(u) {
		ret = true
	}
	return ret
}


func (job *CronJob) updateNextTime (u time.Time)  {
	job.nextTime = job.expr.Next(u)
}

func (job *CronJob) Clone()  CronJob{

	newJob := CronJob{}
	newJob.name = job.name
	newJob.expr = job.expr
	newJob.nextTime = job.nextTime

	return newJob
}